<template>

</template>

<script>
import { loginByToken} from "@/api/user";
export default {
  name: "index",
  data() {
    return {
      loading: false,
      form: {
        captcha: '', // 验证码
        checkKey: '', // 	验证码key
        password: '', // 密码
        username: '', // 账号
        provisionalToken:''
      }
    }
  },
  created() {
    this.onLogin()
  },
  methods: {
    onLogin() {
      this.loading = true;
      this.form['provisionalToken'] = this.$route.query['provisionalToken']
      loginByToken(this.form).then((res)=>{
        this.loading = false;
        localStorage.setItem('USER_TOKEN', res.result.xaccessToken);
        this.$store.commit('setUserToken', res.result.xaccessToken);
        this.$Message.success(this.$t('login.loginSuccess'));
        this.$store.dispatch('getUserInfo');
        if(this.$route.query.redirection) {
          this.$router.push(this.$route.query.redirection);
        } else {
          this.$router.push('/');
        }
      }).catch(()=>{
        this.loading = false;
      })
    }
  }
}
</script>

<style scoped lang="less">

</style>